unit ulistafornecedor;

interface

uses
  variants, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, StdCtrls, Grids, DBGrids, ExtCtrls, ComCtrls, Buttons;

type

THackDBGrid = class(TDBGrid);

  Tflistafornecedor = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Edit1: TEdit;
    DBGrid1: TDBGrid;
    StatusBar1: TStatusBar;
    Panel5: TPanel;
    SpeedButton1: TSpeedButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Edit1Change(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    procedure AppHint(Sender : TObject);
    { Private declarations }
  public
  st, controle:string;
    { Public declarations }
  end;

var
  flistafornecedor: Tflistafornecedor;

implementation

uses upedidofornecedor, Unpagar, udm, uentrada;



procedure tflistafornecedor.AppHint(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := Application.Hint;
end;

{$R *.DFM}

procedure Tflistafornecedor.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin



	        Application.OnHint := nil;
        fdm.tbfornecedor.close;
         flistafornecedor.release;
end;

procedure Tflistafornecedor.Edit1Change(Sender: TObject);
begin
        fdm.tbfornecedor.setrange ([edit1.text], ['Z']);
end;

procedure Tflistafornecedor.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
       if key = 13 then
        DBGrid1DblClick(self);
       if key = 27 then close;

        if key = 40 then fdm.tbfornecedor.next;
        if key = 38 then fdm.tbfornecedor.prior;
end;

procedure Tflistafornecedor.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
       if key = 13 then
        DBGrid1DblClick(self);
       if key = 27 then close;
end;

procedure Tflistafornecedor.FormActivate(Sender: TObject);
begin

 THackDBGrid(DBGrid1).FixedCols := 4;
 (fdm.tbfornecedor.fieldbyname ('codigo') as tfloatfield).displayformat := '000000';
end;

procedure Tflistafornecedor.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Comp: Trichedit; // * variável Comp da classe TMemo
  texto : string;
begin
        if key = 27 then close;

        if key = vk_f1 then begin

  Comp := Trichedit.Create (Self);  // * cria o componente Memo
  Comp.Parent := Self;    // * exibe o componente criado

  if fileexists (extractfilepath(paramstr(0)) + '\ajuda\ajudalistafornecedor.txt') then
   comp.lines.loadfromfile (extractfilepath(paramstr(0)) + '\ajuda\ajudalistafornecedor.txt');

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);

  end;
end;

procedure Tflistafornecedor.DBGrid1DblClick(Sender: TObject);
begin

        if st='entrada' then begin
         fentrada.tbentrada.edit;
          fentrada.tbentrada['codigo'] := fdm.tbfornecedor['codigo'];
           end;

        if st='pedido' then begin
         fpedidofornecedor.tbpedido.edit;
          fpedidofornecedor.tbpedido['codigo'] := fdm.tbfornecedor['codigo'];
           end;

        if st='pagar' then begin
         fdm.tbpagar.edit;
          fdm.tbpagar['codigo'] := fdm.tbfornecedor['codigo'];
           end;


           close;

end;

procedure Tflistafornecedor.FormCreate(Sender: TObject);
begin
     Application.OnHint := AppHint;
end;

procedure Tflistafornecedor.SpeedButton1Click(Sender: TObject);
var
MSG, st: STRING;
begin


   if fdm.tbfornecedor['fantasia'] <> null then
    st := fdm.tbfornecedor['fantasia'];

    with fdm.query1 do begin
     close;
      sql.clear;
       sql.add ('select distinct nome from tbentradaitem where fantasia = "'+ st+'"');
        open;
         end;

    while not fdm.query1.Eof do begin
    if fdm.query1['nome'] <> null then
    msg := msg + fdm.query1['nome']+ #13;
    fdm.query1.next;
    end;

    showmessage('PRODUTOS COMPRADOS:' + #13 + #13 + msg);


end;

end.
